package sbt.metamodel;
        
import java.util.Date;
import java.util.Map;

/**
 * I represent a PrimaryTrace.
 * @author pa
 *
 */
public class PrimaryTrace extends AbstractTrace {
	
	private String origin, model;
	
	/**
	 * @param model  the URI of this trace's model
	 * @param origin  an origin (either ISO datetime or opaque)
	 */
	public PrimaryTrace(String model, String origin) {
		this.origin = origin;
		this.model = model;
	}
	
	@Override
	public String getOrigin() {
		return origin;
	}
	
	/**
	 * Set the origin of this trace.
	 * 
	 * @param newOrigin  an origin (either ISO datetime or opaque)
	 */
	public void setOrigin(String newOrigin) {
		origin = newOrigin;
		notifyAllMetadataChange();
	}

	/**
	 * Set the origin of this trace.
	 * <p>
	 * newOrigin will be formatted according to
	 * {@link AbstractTrace#DATE_FORMAT}.
	 * 
	 * @param newOrigin  an origin as a date
	 */
	public void setOrigin(Date newOrigin) {
		origin = DATE_FORMAT.format(newOrigin);
		notifyAllMetadataChange();
	}

	/**
	 * The model URI of this trace.
	 * @return the model URI
	 */
	public String getModel() {
		return model;
	}
	
	/**
	 * Set the model URI of this trace.
	 * @param newModel
	 */
	public void setModel(String newModel) {
		model = newModel;
		notifyAllMetadataChange();
	}
            
	@Override 
    public Obsel createObsel(String type, long begin, long end, String subject,
                Map<String, Object> attributes, Map<String, Obsel> related,
                Map<String, Obsel> relating) {
        return super.createObsel(type, begin, end, subject, attributes,
                related, relating);
    }

	@Override
    public void clearObsels() {
    	super.clearObsels();
    }
    
    
    // shortcut methods
    
    /**
     * Create an obsel with no incoming relation.
     * @see #createObsel(String, long, long, String, Map, Map, Map)
     */
    public Obsel createObsel(String type, int begin, int end, String subject,
                   Map<String, Object> attributes,
                   Map<String, Obsel> related) {
        return createObsel(type, begin, end, subject, attributes, related, null);
    }

    /**
     * Create an obsel with no relation.
     * @see #createObsel(String, long, long, String, Map, Map, Map)
     */
    public Obsel createObsel(String type, int begin, int end, String subject,
                   Map<String, Object> attributes) {
        return createObsel(type, begin, end, subject, attributes, null, null);
    }

    /**
     * Create an obsel with no attribute nor relation.
     * @see #createObsel(String, long, long, String, Map, Map, Map)
     */
    public Obsel createObsel(String type, int begin, int end, String subject) {
        return createObsel(type, begin, end, subject, null, null, null);
    }

    /**
     * Create an instant obsel.
     * @see #createObsel(String, long, long, String, Map, Map, Map)
     */
    public Obsel createObsel(String type, int begin, String subject,
                   Map<String, Object> attributes,
                   Map<String, Obsel> related, Map<String, Obsel> relating) {
        return createObsel(type, begin, begin, subject, attributes, related,
        		null);
    }

    /**
     * Create an instant obsel with no incoming relation.
     * @see #createObsel(String, long, long, String, Map, Map, Map)
     */
    public Obsel createObsel(String type, int begin, String subject,
                   Map<String, Object> attributes,
                   Map<String, Obsel> related) {
        return createObsel(type, begin, begin, subject, attributes, related,
        		null);
    }

    /**
     * Create an instant obsel with no relation.
     * @see #createObsel(String, long, long, String, Map, Map, Map)
     */
    public Obsel createObsel(String type, int begin, String subject,
                   Map<String, Object> attributes) {
        return createObsel(type, begin, begin, subject, attributes, null, null);
    }

    /**
     * Create an instant obsel with no attribute nor relation.
     * @see #createObsel(String, long, long, String, Map, Map, Map)
     */
    public Obsel createObsel(String type, int begin, String subject) {
        return createObsel(type, begin, begin, subject, null, null, null);
    }
}
